package com.example.demo.service.impl;

import com.example.demo.model.Clazz;
import com.example.demo.model.Student;
import com.example.demo.repository.ClazzRepository;
import com.example.demo.repository.StudentRepository;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lafengmaker
 * @title: StudentServiceImpl
 * @projectName demo
 * @description: empty
 * @email ywjwy365@126.com
 * @date 2019-10-09 13:42
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    StudentRepository studentRepository;
    @Autowired
    ClazzRepository clazzRepository;

    @Override
    @Transactional
    public void addStudent(Student student, Integer classId) {
        Clazz clazz=this.clazzRepository.getOne(classId);
        System.out.println(clazz.getName());
        clazz.setName("初二1");
        Student s=this.studentRepository.getOne(5);
        s.setClazz(clazz);
        this.studentRepository.save(s);
    }
}
